package com.fl.nacostest.controller;

import com.alibaba.fastjson.JSON;
import com.fl.nacostest.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: fulin
 * @Date: 2022/08/04/15:20
 * @Description:
 */
@RestController
public class KafkaController {

    public static String TOPIC_NAME = "my-replicated-topic4";

    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;
    static SimpleDateFormat fm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @RequestMapping("/send")
    public void send() {
        String date = fm.format(new Date());
        kafkaTemplate.send(TOPIC_NAME, 0, "key", JSON.toJSONString(new Log(date, "" + System.currentTimeMillis())));
    }

}
